package com.xuelang.pipeline.client.pipeline.enums;

import lombok.Getter;

/**
 * @author liuyuan.ly
 * @since 2024/9/5 14:20
 */
@Getter
public enum ArtifactTypeEnum {
    /**
     * 通用制品库
     */
    GENERIC("GENERIC", "通用制品库"),
    /**
     * 镜像仓库
     */
    DOCKER("DOCKER", "镜像仓库"),
    /**
     * Maven仓库
     */
    MAVEN("MAVEN", "Maven仓库"),
    /**
     * Npm仓库
     */
    NPM("NPM", "Npm仓库");

    /**
     * key
     */
    private final String key;
    /**
     * 名称
     */
    private final String name;

    ArtifactTypeEnum(String key, String name) {
        this.key = key;
        this.name = name;
    }

    public static boolean isValid(String artifactType) {
        for (ArtifactTypeEnum item : ArtifactTypeEnum.values()) {
            if (item.key.equals(artifactType)) {
                return true;
            }
        }
        return false;
    }
    public static ArtifactTypeEnum getByKey(String key) {
        for (ArtifactTypeEnum item : ArtifactTypeEnum.values()) {
            if (item.key.equals(key)) {
                return item;
            }
        }
        throw new IllegalArgumentException("key:" + key);
    }
}
